<?php

require_once('../include/GeneralTop.php');
require('../include/class/db.php');

$db = new db;

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the session varialbles
  $_SESSION['Index_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['Index_Username']);
  unset($_SESSION['member_id']);
  unset($_SESSION['MM_Username_id']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['MM_Username']);
  unset($_SESSION['PrevUrl']);
	
  $logoutGoTo = "../index.php";
  if ($logoutGoTo) {
   header("Location: $logoutGoTo");
    exit;
  }
}

if ((isset($_POST["submit"]))) {
    if('edit' == $_POST['action']) {
	    $check_username = "select member_id from member_info where member_login='".$_POST['member_login']."' and member_id!='".$_POST['member_id']."'";
    	$check_username_res = $db->query($check_username);
    	$fail = false;
    	if(0 < $db->num($check_username_res)) {
    		$_GET['result'] = "会员网名已被注册，请换一个会员网名<br>";
    		$fail = true;
    	}
    	
    	$check_mail = "select member_id from member_info where Email_account='".$_POST['Email_account']."' and member_id!='".$_POST['member_id']."'";
    	$check_mail_res = $db->query($check_mail);
    	if(0 < $db->num($check_mail_res)) {
    		$_GET['result'] .= "Email地址已被使用，请换一个Email地址<br>";
    		$fail = true;
    	}
    	
    	if(!$fail) {
		    if(1 < count($_POST['Volunteer_Type'])) {
	    		$vol_type = '';
	    		foreach($_POST['Volunteer_Type'] as $_key => $_value) {
	    			$vol_type .= $_value.',';
	    		}
	    		$vol_type = substr($vol_type, 0, -1);
	    	}
	    	else {
	    		$vol_type = $_POST['Volunteer_Type'];
	    	}
		    $updateSQL = sprintf("UPDATE member_info SET member_login=%s, member_name=%s, Sex=%s, Identity_id=%s, 
									Phone_number1=%s, Phone_number2=%s, Email_account=%s, Address=%s, Distict=%s, Zip=%s, 
									profession_type=%s, Pet_YN=%s, Pet_type=%s, Pet_breed=%s, Pet_count=%s, be_pay_member_YN=%s,
									Volunteer_YN=%s, Volunteer_Type=%s, Other_Volunteer=%s, foreign_language=%s, foster_fee_YN=%s, 
									foster_type=%s, foster_fee_amount=%s, interest_skills=%s, Experience=%s 
									WHERE member_id=%s",
		                       GetSQLValueString($_POST['member_login'], "text"),
		                       GetSQLValueString($_POST['member_name'], "text"),
		                       GetSQLValueString($_POST['Sex'], "int"),
		                       GetSQLValueString($_POST['Identity_id'], "text"),
		                       GetSQLValueString($_POST['Phone_number1'], "text"),
		                       GetSQLValueString($_POST['Phone_number2'], "text"),
		                       GetSQLValueString($_POST['Email_account'], "text"),
		                       GetSQLValueString($_POST['Address'], "text"),
		                       GetSQLValueString($_POST['Distict'], "text"),
		                       GetSQLValueString($_POST['Zip'], "text"),
		                       GetSQLValueString($_POST['profession_type'], "text"),
		                       GetSQLValueString($_POST['Pet_YN'], "text"),
		                       GetSQLValueString($_POST['Pet_type'], "int"),
		                       GetSQLValueString($_POST['Pet_breed'], "text"),
		                       GetSQLValueString($_POST['Pet_count'], "text"),                       
		                       GetSQLValueString($_POST['be_pay_member_YN'], "int"),
		                       GetSQLValueString($_POST['Volunteer_YN'], "int"),
		                       GetSQLValueString($vol_type, "text"),
		                       GetSQLValueString($_POST['Other_Volunteer'], "text"),
		                       GetSQLValueString($_POST['foreign_language'], "text"),
		                       GetSQLValueString($_POST['foster_fee_YN'], "text"),
		                       GetSQLValueString($_POST['foster_type'], "text"),
		                       GetSQLValueString($_POST['foster_fee_amount'], "text"),
		                       GetSQLValueString($_POST['interest_skills'], "text"),
		                       GetSQLValueString($_POST['Experience'], "text"),
		                       GetSQLValueString($_POST['member_id'], "int"));
			//echo $updateSQL;
		    $db->query($updateSQL);
		    
		    if($_POST['password'] != '') {
		    	$update_password = "update member_info set password='".md5($_POST['password'])."' where member_id=".$_POST['member_id'];
		    	$db->query($update_password);
		    }
		    
		    if((int)$_POST['be_pay_member_YN'] !== (int)$_POST['want_be_pay_old'] && 1 === (int)$_POST['be_pay_member_YN']) {
		    	$subject = 'A member want to be paid member';
		    	$message = 'Member (user login: '.$_POST['member_login'].') want to be paid member.
You can search him/her out by user login in Admin Panel.';
		    	mail(MAIL_PAID_DL, $subject, $message);
		    	$pay_int = 1;
		    }
		    else {
		    	$pay_int = 0;
		    }
		    
		    $member_id = $_POST['member_id'];
		    header("location:".$_SERVER['PHP_SELF']."?result=suc&member_id=".$member_id."&action=".$_POST['action']."&vo=".$_POST['Volunteer_YN']."&pay=".$pay_int);
    	}
    }
    else if('new' == $_POST['action']) {
    	$check_username = "select member_id from member_info where member_login='".$_POST['member_login']."'";
    	$check_username_res = $db->query($check_username);
    	$fail = false;
    	if(0 < $db->num($check_username_res)) {
    		$_GET['result'] = "会员网名已被注册，请换一个会员网名<br>";
    		$fail = true;
    	}
    	
    	$check_mail = "select member_id from member_info where Email_account='".$_POST['Email_account']."'";
    	$check_mail_res = $db->query($check_mail);
    	if(0 < $db->num($check_mail_res)) {
    		$_GET['result'] .= "Email地址已被使用，请换一个Email地址<br>";
    		$fail = true;
    	}

    	if(!$fail) {
	    	$role = 4; //ordinary member
	    	if(1 < count($_POST['Volunteer_Type'])) {
	    		$vol_type = '';
	    		foreach($_POST['Volunteer_Type'] as $_key => $_value) {
	    			$vol_type .= $_value.',';
	    		}
	    		$vol_type = substr($vol_type, 0, -1);
	    	}
	    	else {
	    		$vol_type = $_POST['Volunteer_Type'];
	    	}
	    	$insertSQL = sprintf("INSERT INTO member_info SET member_login=%s, password=%s, member_name=%s, Sex=%s, Identity_id=%s, 
									Phone_number1=%s, Phone_number2=%s, Email_account=%s, Address=%s, Distict=%s, Zip=%s, 
									profession_type=%s, Pet_YN=%s, Pet_type=%s, Pet_breed=%s, Pet_count=%s, be_pay_member_YN=%s,
									Volunteer_YN=%s, Volunteer_Type=%s, Other_Volunteer=%s, foreign_language=%s, foster_fee_YN=%s, 
									foster_type=%s, foster_fee_amount=%s, interest_skills=%s, Experience=%s, role=%s, register_date=%s",
		                       GetSQLValueString($_POST['member_login'], "text"),
		                       GetSQLValueString(md5($_POST['password']), "text"),
		                       GetSQLValueString($_POST['member_name'], "text"),
		                       GetSQLValueString($_POST['Sex'], "int"),
		                       GetSQLValueString($_POST['Identity_id'], "text"),
		                       GetSQLValueString($_POST['Phone_number1'], "text"),
		                       GetSQLValueString($_POST['Phone_number2'], "text"),
		                       GetSQLValueString($_POST['Email_account'], "text"),
		                       GetSQLValueString($_POST['Address'], "text"),
		                       GetSQLValueString($_POST['Distict'], "text"),
		                       GetSQLValueString($_POST['Zip'], "text"),
		                       GetSQLValueString($_POST['profession_type'], "text"),
		                       GetSQLValueString($_POST['Pet_YN'], "text"),
		                       GetSQLValueString($_POST['Pet_type'], "int"),
		                       GetSQLValueString($_POST['Pet_breed'], "text"),
		                       GetSQLValueString($_POST['Pet_count'], "text"),                       
		                       GetSQLValueString($_POST['be_pay_member_YN'], "int"),
		                       GetSQLValueString($_POST['Volunteer_YN'], "int"),
		                       GetSQLValueString($vol_type, "text"),
		                       GetSQLValueString($_POST['Other_Volunteer'], "text"),
		                       GetSQLValueString($_POST['foreign_language'], "text"),
		                       GetSQLValueString($_POST['foster_fee_YN'], "text"),
		                       GetSQLValueString($_POST['foster_type'], "text"),
		                       GetSQLValueString($_POST['foster_fee_amount'], "text"),
		                       GetSQLValueString($_POST['interest_skills'], "text"),
		                       GetSQLValueString($_POST['Experience'], "text"),
		                       GetSQLValueString($role, "int"),
		                       GetSQLValueString(date("Y-m-d H:i:s"), "text"));
			//echo $insertSQL;die();
		    $db->query($insertSQL);
		    
		    $member_id = $db->insert_id();
		    
		    //set session after register
		    $_SESSION['Index_Username'] = $_POST['member_login'];
		    $_SESSION['MM_UserGroup'] = $role;
		    $_SESSION['member_id'] = $member_id;
		    $_SESSION['MM_Username_id'] = $member_id;
			  
			if(MEMBER_SITE_ADMIN === (int)$row['role'] || MEMBER_CONTENT_ADMIN === (int)$row['role'] || MEMBER_PAID === (int)$row['role']) {
			  	$_SESSION['MM_Username'] = $loginUsername;
			}
	    
		    if((int)$_POST['be_pay_member_YN'] !== (int)$_POST['want_be_pay_old'] && 1 === (int)$_POST['be_pay_member_YN']) {
		    	$subject = 'A member want to be paid member';
		    	$message = 'Member (user login: '.$_POST['member_login'].') want to be paid member.
You can search him/her out by user login in Admin Panel.';
		    	mail(MAIL_PAID_DL, $subject, $message);
		    }
		    
		    header("location:".$_SERVER['PHP_SELF']."?result=suc&member_id=".$member_id."&action=".$_POST['action']."&vo=".$_POST['Volunteer_YN']."&pay=".$_POST['be_pay_member_YN']);
    	}
    }
}

$sql = sprintf("SELECT * FROM member_info WHERE member_id = %s", GetSQLValueString($_SESSION['member_id'], "int"));
$res = $db->query($sql);
$row = $db->fetch($res);

require("../include/header.php");
if ('edit' == $_GET['action'] && !isset($_SESSION['Index_Username'])) {
	die('<div style="text-align:center">'.MSG_PERMISSION_DENIED.'</div>');
}
?>
<script src="../include/js/calendar.js" type="text/javascript"></script>
<table width="1001" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="229" valign="top" background="../images/fen_20.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="228" height="65" valign="top" background="../images/fen_07.gif"><table width="100%" height="34" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td height="34"></td>
            </tr>
          </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="8"></td>
                <td><div align="center" class="font_16px_white_B"><?php echo TEXT_PROFILE?></div></td>
                <td width="3"></td>
              </tr>
            </table></td>
        </tr>
      </table>
      </td>
    <td width="782" align="left" valign="top" height="100%">
<table width="777" border="0" align="left" cellpadding="0" cellspacing="0" valign="top" class="font_12px_gray">
  <tr>
    <td width="777" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="51" valign="top" background="../images/fen_09.gif"><table width="95%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="16">&nbsp;</td>
            </tr>
          </table>
          <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="14"><img src="../images/fen_12.gif" width="7" height="29"></td>
              <td width="405"><span class="font_16px_black_B"><?php echo 'edit' == $_GET['action'] ? TEXT_MODIFY_PROFILE : TEXT_NEW_USER?></span></td>
              <td width="15">&nbsp;</td>
              <td width="299">&nbsp;</td>
              </tr>
          </table></td>
        </tr>
      </table>
      <form id="form1" name="form1" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return check_form();">
  <table align="center" width="700" border="0" cellpadding="5" cellspacing="1" class="font_12px_gray">
    <?php
    if('edit' == $_GET['action'] || 'edit' == $_POST['action']) {
		$pass_color = '';
		$pass_hint = '(留空就是不改)';
	}
	else {
		$pass_color = '<font color="red">*</font>';
		$pass_hint = '';
	}
	
    if($_GET['result']) {
		if('suc' == $_GET['result']) {
			if('edit' == $_GET['action']) {
				$suc_text = "更新成功...";
			}
			else {
				$suc_text = "注册成功...";
			}
			if(1 === (int)$_GET['pay']){
				$suc_text .= "<br>您选择了愿意成为付费会员，管理员会根据您的信息做相应处理，这可能需要一到两天的时间。";
			}
			if(1 === (int)$_GET['vo']){
				$suc_text .= "<br>您选择了愿意成为志愿者，管理员会根据您的信息做相应处理，这可能需要一到两天的时间。";
			}
			$suc_text = '<font color="green">'.$suc_text.'</font>';
		}
		else {
			$suc_text = '<font color="red">'.$_GET['result'].'</font>';
			$_GET['action'] = $_POST['action'];			
			$row = $_POST;
		}
    ?>
    <tr valign="baseline">
      <td colspan="2" nowrap="nowrap" align="center"><font color="green"><?php echo $suc_text?></font></td>
    </tr>
    <?php
    }
    ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><font color="red">*</font> 会员网名</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="text" name="member_login" id="member_login" value="<?php echo htmlentities($row['member_login'], ENT_COMPAT, 'utf-8')?>"/>
      </label></td>
      <td widtd="118">&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><?php echo $pass_color?> 密码</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="password" name="password" id="password" /> <?php echo $pass_hint?>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><font color="red">*</font> 会员真实名字</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="text" name="member_name" id="member_name" value="<?php echo htmlentities($row['member_name'], ENT_COMPAT, 'utf-8');?>"/>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">性别</td>
      <td widtd="75%" align="left" valign="middle"><p>
      <?php
      if(MEMBER_MALE === (int)$row['Sex']) {
      	  $male_check = 'checked';
      	  $female_check = '';
      }
      else {
      	  $male_check = '';
      	  $female_check = 'checked';
      }
      ?>
          <label>
            <span id="rgGender_0">
			<input type="radio" name="Sex" value="<?php echo MEMBER_MALE?>" id="rgGender_0" <?php echo $male_check?>/>
			男</span></label>
          <span id="rgGender_">
          <label>
            <input type="radio" name="Sex" value="<?php echo MEMBER_FEMALE?>" id="rgGender_1" <?php echo $female_check?>/>
           	 女</label>
      </span></p></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">身份证号</td>
      <td widtd="75%" align="left" valign="middle"><input name="Identity_id" type="text" id="Identity_id" maxlengtd="18" value="<?php echo htmlentities($row['Identity_id'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">固定电话</td>
      <td widtd="75%" align="left" valign="middle"><input name="Phone_number1" type="text" id="Phone_number1" maxlengtd="20"  value="<?php echo htmlentities($row['Phone_number1'], ENT_COMPAT, 'utf-8')?>"/></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><font color="red">*</font> 联系手机</td>
      <td widtd="75%" align="left" valign="middle"><input name="Phone_number2" type="text" id="Phone_number2" maxlengtd="20" value="<?php echo htmlentities($row['Phone_number2'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><font color="red">*</font> 邮件地址</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="Email_account" id="Email_account" value="<?php echo htmlentities($row['Email_account'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">住家地址</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="Address" id="Address" value="<?php echo htmlentities($row['Address'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><font color="red">*</font> 上海区县</td>
      <td widtd="75%" align="left" valign="middle"><select name="Distict" id="Distict">
        <option value="">-请选择-</option>
        <?php
        foreach($district_arr as $_key => $_value) {
        	if($_value == $row['Distict']) {
        		echo '<option value="'.$_value.'" selected>'.$_value.'</option>';
        	}
        	else {
        		echo '<option value="'.$_value.'">'.$_value.'</option>';
        	}
        }        
        ?>
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">邮政编码</td>
      <td widtd="75%" align="left" valign="middle"><input name="Zip" type="text" id="Zip" maxlengtd="10" value="<?php echo htmlentities($row['Zip'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">职业类型</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <select name="profession_type" id="profession_type">
            <option value="">-请选择-</option>
            <?php
	        foreach($profession_arr as $_key => $_value) {
	        	if($_value == $row['profession_type']) {
	        		echo '<option value="'.$_value.'" selected>'.$_value.'</option>';
	        	}
	        	else {
	        		echo '<option value="'.$_value.'">'.$_value.'</option>';
	        	}
	        }        
	        ?>
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <?php
      if('Y' == $row['Pet_YN']) {
      	  $yes = 'checked';
      	  $no = '';
      }
      else {
      	  $yes = 'checked';
      	  $no = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">家中是否饲养宠物？</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="radio" name="Pet_YN" value="Y" id="Pet_YN" <?php echo $yes?>/>
        是
      </label>
        <label>
          <input type="radio" name="Pet_YN" value="N" id="Pet_YN" <?php echo $no?> />
      否</label></td>
      <td>&nbsp;</td>
    </tr>
    <?php
      if(1 === (int)$row['Pet_type']) {
      	  $dog = 'checked';
      	  $cat = '';
      	  $other = '';
      	  $both = '';
      }
      else if(2 === (int)$row['Pet_type']) {
      	  $dog = '';
      	  $cat = 'checked';
      	  $other = '';
      	  $both = '';
      }
      else if(3 === (int)$row['Pet_type']) {
      	  $dog = '';
      	  $cat = '';
      	  $other = 'checked';
      	  $both = '';
      }
      else {
      	  $dog = '';
      	  $cat = '';
      	  $other = '';
      	  $both = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">饲养何种宠物？</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="radio" name="Pet_type" value="<?php echo PET_TYPE_CAT?>" id="Pet_type" <?php echo $cat?>/>
        猫</label>
        <label>
          <input type="radio" name="Pet_type" value="<?php echo PET_TYPE_DOG?>" id="Pet_type" <?php echo $dog?>/>
      狗</label>
      <input type="radio" name="Pet_type" value="<?php echo PET_TYPE_BOTH?>" id="Pet_type"  <?php echo $both?>/>
      猫狗都有</label>
      <input type="radio" name="Pet_type" value="<?php echo PET_TYPE_OtdER?>" id="Pet_type" <?php echo $otder?>/>
      其他</label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">宠物品种</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="Pet_breed" id="Pet_breed" value="<?php echo htmlentities($row['Pet_breed'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">宠物总数</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="Pet_count" id="Pet_count" value="<?php echo htmlentities($row['Pet_count'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    
    <?php
      if(1 === (int)$row['be_pay_member_YN']) {
      	  $yes = 'checked';
      	  $no = '';
      }
      else if(2 === (int)$row['be_pay_member_YN']) {
      	  $yes = '';
      	  $no = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">是否愿意成为付费会员</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="radio" name="be_pay_member_YN" value="1" id="be_pay_member_YN" <?php echo $yes?>/>
        愿意
      </label>
        <label>
          <input type="radio" name="be_pay_member_YN" value="2" id="be_pay_member_YN" <?php echo $no?>/>
          不愿意
        </label></td>
      <td>&nbsp;</td>
    </tr>
    <input type="hidden" name="want_be_pay_old" value="<?php echo (int)$row['be_pay_member_YN']?>">
    <?php
      if(1 === (int)$row['Volunteer_YN']) {
      	  $yes = 'checked';
      	  $no = '';
      }
      else if(2 === (int)$row['Volunteer_YN']) {
      	  $yes = '';
      	  $no = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">是否愿意成为志愿者</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="radio" name="Volunteer_YN" value="1" id="Volunteer_YN" <?php echo $yes?>/>
        愿意
      </label>
        <label>
          <input type="radio" name="Volunteer_YN" value="2" id="Volunteer_YN" <?php echo $no?>/>
          不愿意
        </label></td>
      <td>&nbsp;</td>
    </tr>
    <?php
      $type1 = '';
  	  $type2 = '';
  	  $type3 = '';
  	  $type4 = '';
  	  $type5 = '';
  	  $type6 = '';
  	  if(is_array($row['Volunteer_Type'])) {
  	  	  $vol_type = $row['Volunteer_Type'];
  	  }
  	  else {
	  	  $vol_type = explode(",", $row['Volunteer_Type']);
  	  }
      if(in_array(1, $vol_type)) {
      	  $type1 = 'checked';
      }
      if(in_array(2, $vol_type)) {
      	  $type2 = 'checked';
      }
      if(in_array(3, $vol_type)) {
      	  $type3 = 'checked';
      }
      if(in_array(4, $vol_type)) {
      	  $type4 = 'checked';
      }
      if(in_array(5, $vol_type)) {
      	  $type5 = 'checked';
      }
      if(in_array(6, $vol_type)) {
      	  $type6 = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="top" scope="row">志愿者类型</td>
      <td widtd="75%" align="left" valign="middle"><p>
        <label>
          <input type="checkbox" name="Volunteer_Type[]" id="Volunteer_Type" value="1" <?php echo $type1?>/>
          <?php echo TEXT_VOLUNTEER_TYPE_1?></label>
        <br />
        <label>
          <input type="checkbox" name="Volunteer_Type[]" id="Volunteer_Type" value="2" <?php echo $type2?>/>
          <?php echo TEXT_VOLUNTEER_TYPE_2?></label>
        <br />
        <label>
          <input type="checkbox" name="Volunteer_Type[]" id="Volunteer_Type" value="3" <?php echo $type3?>/>
          <?php echo TEXT_VOLUNTEER_TYPE_3?></label>
        <br />
        <label>
          <input type="checkbox" name="Volunteer_Type[]" id="Volunteer_Type" value="4" <?php echo $type4?>/>
          <?php echo TEXT_VOLUNTEER_TYPE_4?></label>
        <br />
        <label>
          <input type="checkbox" name="Volunteer_Type[]" id="Volunteer_Type" value="5" <?php echo $type5?>/>
          <?php echo TEXT_VOLUNTEER_TYPE_5?></label>
        <br />
        <label>
          <input type="checkbox" name="Volunteer_Type[]" id="Volunteer_Type" value="6" <?php echo $type6?>/>
          <?php echo TEXT_VOLUNTEER_TYPE_6?></label>
        <br />
        <br />
      </p></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">其它志愿者</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="Other_Volunteer" id="Other_Volunteer" value="<?php echo htmlentities($row['Other_Volunteer'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">外语能力</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="foreign_language" value="<?php echo htmlentities($row['foreign_language'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <?php
      if(1 === (int)$row['foster_fee_YN']) {
      	  $yes = 'checked';
      	  $no = '';
      }
      else if(2 === (int)$row['foster_fee_YN']) {
      	  $yes = '';
      	  $no = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">如果可提供寄养，是否可免费寄养</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="radio" name="foster_fee_YN" value="<?php echo FREE_FOSTER_YES?>" id="foster_fee_YN" <?php echo $yes?>/>
        愿意</label>
        <label>
          <input type="radio" name="foster_fee_YN" value="<?php echo FREE_FOSTER_NO?>" id="foster_fee_YN" <?php echo $no?>/>
      不愿意</label></td>
      <td>&nbsp;</td>
    </tr>
    <?php
      if(1 === (int)$row['foster_type']) {
      	  $dog = 'checked';
      	  $cat = '';
      	  $both = '';
      }
      else if(2 === (int)$row['foster_type']) {
      	  $dog = '';
      	  $cat = 'checked';
      	  $both = '';
      }
      else {
      	  $dog = '';
      	  $cat = '';
      	  $both = 'checked';
      }
      ?>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row"><p>可寄养何种宠物？</p></td>
      <td widtd="75%" align="left" valign="middle"><label>
        <input type="radio" name="foster_type" value="<?php echo PET_TYPE_CAT?>" id="foster_type" <?php echo $cat?>/>
        猫</label>
        <label>
          <input type="radio" name="foster_type" value="<?php echo PET_TYPE_DOG?>" id="foster_type" <?php echo $dog?>/>
      狗</label>
      <input type="radio" name="foster_type" value="<?php echo PET_TYPE_BOTH?>" id="foster_type"  <?php echo $both?>/>
      猫狗都可以</label>
      </td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">如果要有偿寄养，收费是多少？</td>
      <td widtd="75%" align="left" valign="middle"><input type="text" name="foster_fee_amount" id="foster_fee_amount" value="<?php echo htmlentities($row['foster_fee_amount'], ENT_COMPAT, 'utf-8')?>" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">兴趣/专长</td>
      <td widtd="75%" align="left" valign="middle"><label>
        <textarea name="interest_skills" id="interest_skills" cols="45" rows="5"><?php echo htmlentities($row['interest_skills'], ENT_COMPAT, 'utf-8')?></textarea>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td widtd="25%" align="right" valign="middle" scope="row">工作/义工/动物方面的经验</td>
      <td widtd="75%" align="left" valign="middle"><textarea name="Experience" id="Experience" cols="45" rows="5"><?php echo htmlentities($row['Experience'], ENT_COMPAT, 'utf-8')?></textarea></td>
      <td>&nbsp;</td>
    </tr>
    <?php
    if('edit' == $_GET['action']) {
    	$_value = '更新';
    }
    else {
    	$_value = '注册';
    }
    ?>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" name="submit" id="submit" value="<?php echo $_value?>" /></td>
    </tr>
    <?php
    if(MEMBER_PAID === (int)$row['role']) {
    ?>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><a href="../Admin/HappyHome.php">去Admin Panel</a></td>
    </tr>
    <?php
    }
    ?>
  </table>
  <input type="hidden" name="member_id" value="<?php echo $row['member_id']; ?>" />
  <input type="hidden" name="action" value="<?php echo $_GET['action']?>">
</form>
	</td>
  </tr>
</table>
</td>

<table width="1001" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="9" background="../images/fen_03.gif"></td>
  </tr>
</table>


<table width="1001" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center" valign="top" bgcolor="F7F7F7"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="10"></td>
      </tr>
    </table>
      <table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="11" height="26"><img src="../images/copyright_01.gif" width="11" height="26"></td>
          <td background="../images/copyright_03.gif" class="font_12px_gray"><div align="center">上海市畜牧兽医学会小动物保护分会   2009年   版权所有    沪ICP备06004930号</div></td>
          <td width="12"><img src="../images/copyright_04.gif" width="12" height="26"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="10"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="10"><div align="center" class="font_12px_gray">电话：021-61432446  传真：021-61432448  Email: ssapa.info@yahoo.com.cn (中文), helpttheanimals@yahoo.cn (English)</div></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td height="10"></td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>

<script language="JavaScript" type="text/javascript">
function check_form() {
	if (document.getElementById('member_login').value == '') {
		alert('请输入会员网名');
		document.getElementById('member_login').focus();
		return false;
	}
	<?php
	if('new' == $_GET['action']) {
	?>
	if (document.getElementById('password').value == '') {
		alert('请输入密码');
		document.getElementById('password').focus();
		return false;
	}
	<?php
	}
	?>
	if (document.getElementById('member_name').value == '') {
		alert('请输入真实姓名');
		document.getElementById('member_name').focus();
		return false;
	}
	if (document.getElementById('Phone_number2').value == '') {
		alert('请输入手机');
		document.getElementById('Phone_number2').focus();
		return false;
	}
	if (document.getElementById('Email_account').value == '') {
		alert('请输入邮件地址');
		document.getElementById('Email_account').focus();
		return false;
	}
	if (document.getElementById('Email_account').value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1) {
		alert('邮件地址格式不正确');
		document.getElementById('Email_account').focus();
		return false;
	}

	if (document.getElementById('Distict').value == '') {
		alert('请选择区县');
		document.getElementById('Distict').focus();
		return false;
	}
	
	return true;
}
</script>